<template>
    <div>
        <div class="ivu-row day-num-item">
            <div class="ivu-col ivu-col-span-4">
                <Button :loading="dayLoading" type="primary" @click="getDayAllNum">查询各统计项</Button>
            </div>
            <div class="ivu-col ivu-col-span-20" v-html="day_all_num"></div>
            <div v-if="dayType === '1'" class="ivu-col ivu-col-span-4">
                <Button :loading="areaLoading" type="primary" @click="getDayAllAreaNum">查询区县统计项</Button>
            </div>
            <div v-if="dayType === '1'" class="ivu-col ivu-col-span-20" v-html="area_num"></div>
            <div v-if="areaType === '1'" class="ivu-col ivu-col-span-4">
                <Button :loading="streetLoading" type="primary" @click="getDayAllStreetNum">查询街道统计</Button>
                <Select v-model="streetType"  style="width:120px">
                    <Option value="于洪区">于洪区</Option>
                    <Option value="浑南区">浑南区</Option>
                    <Option value="康平县">康平县</Option>
                    <Option value="大东区">大东区</Option>
                    <Option value="沈河区">沈河区</Option>
                    <Option value="辽中区">辽中区</Option>
                    <Option value="皇姑区">皇姑区</Option>
                    <Option value="铁西区">铁西区</Option>
                    <Option value="和平区">和平区</Option>
                    <Option value="新民市">新民市</Option>
                    <Option value="沈北新区">沈北新区</Option>
                    <Option value="法库县">法库县</Option>
                    <Option value="苏家屯区">苏家屯区</Option>
                </Select>
            </div>
            <div v-if="areaType === '1'" class="ivu-col ivu-col-span-20" v-html="street_num"></div>
        </div>
        <Table :loading="loading" border :columns="columns2" :data="dataList" size="small">

        </Table>
    </div>
</template>

<script>
import { totalAllUserType, getDayAllNum, getDayAllAreaNum, getDayAllStreetNum } from '@/api/statistics'
import { userChangePwd } from '@/api/user'

export default {
  data () {
    return {
      loading: true,
      columns2: [
        { title: '景区', key: 'title', align: 'center' },
        { title: '人数', key: 'num', align: 'center' }
      ],
      dataList: [],
      day_all_num: '',
      dayLoading: false,
      dayType: '0',
      area_num: '',
      areaLoading: false,
      areaType: '0',
      streetLoading: false,
      street_num: '',
      allNum: '',
      loginName: ''
    }
  },
  methods: {
    init () {
      totalAllUserType().then(ret => {

      })
    },
    getDayAllNum () {
      // 查询各统计项
      getDayAllNum().then(ret => {
        if (ret.data.errcode === 0) {
          this.allnum = ret.data.data.allnum
          this.getDayAllAreaNum()
        } else {
          this.$Message.warning(ret.data.errmsg)
          this.getDayAllNum()
        }
      })
    },
    getDayAllAreaNum () {
      getDayAllAreaNum({ allNum: this.allnum }).then(ret => {
        if (ret.data.errcode === 0) {
          this.area_num = ret.data.data.info.replace(/,/g, '<br/>')
          this.userChangePwd()
        } else {
          this.$Message.warning(ret.data.errmsg)
          this.getDayAllAreaNum()
        }
      })
    },
    userChangePwd () {
      userChangePwd().then(ret => {
        if (ret.data.errcode === 0) {
          this.loginName = ret.data.data.loginName
          this.getDayAllStreetNum()
        } else {
          this.$Message.warning(ret.data.errmsg)
        }
      })
    },
    getDayAllStreetNum () {
      console.log(this.streetType)
      let typee = ''
      if (this.loginName === 'LA00020') {
        typee = '沈河区'
      } else if (this.loginName === 'LA00021') {
        typee = '大东区'
      } else if (this.loginName === 'LA00022') {
        typee = '沈北新区'
      } else if (this.loginName === 'LA00023') {
        typee = '和平区'
      } else if (this.loginName === 'LA00024') {
        typee = '苏家屯区'
      } else if (this.loginName === 'LA00025') {
        typee = '铁西区'
      } else if (this.loginName === 'LA00026') {
        typee = '皇姑区'
      } else if (this.loginName === 'LA00027') {
        typee = '于洪区'
      } else if (this.loginName === 'LA00028') {
        typee = '浑南新区'
      } else if (this.loginName === 'LA00029') {
        typee = '法库县'
      } else if (this.loginName === 'LA00030') {
        typee = '康平县'
      } else if (this.loginName === 'LA00031') {
        typee = '辽中县'
      } else if (this.loginName === 'LA00032') {
        typee = '新民市'
      } else {
        this.$Message.warning('请登录防疫指挥部帐号')
        return false
      }
      let newType = typee + '='
      let num = this.getNum(this.area_num, newType, '<br/>')
      console.log(num)
      getDayAllStreetNum({ areaNum: num, area: typee }).then(ret => {
        if (ret.data.errcode === 0) {
          this.street_num = ret.data.data.info.replace(/,/g, '<br/>')
          this.street_num = this.street_num.replace(/{/g, '')
          this.street_num = this.street_num.replace(/}/g, '')
        } else {
          this.$Message.warning(ret.data.errmsg)
          this.getDayAllStreetNum()
        }
      })
    },
    getNum (str, firstStr, secondStr) {
      if (str === '' || str === null || str === undefined) { // "",null,undefined
        return ''
      }
      if (str.indexOf(firstStr) < 0) {
        return ''
      }
      var subFirstStr = str.substring(str.indexOf(firstStr) + firstStr.length, str.length)
      var subSecondStr = subFirstStr.substring(0, subFirstStr.indexOf(secondStr))
      return subSecondStr
    }

  },
  mounted () {
    this.init()
  }
}
</script>

<style scoped>
    .ivu-col.ivu-col-span-6{
        padding-right: 10px;
        color: #ffffff;
        width: 20%;
    }
    .ivu-col.ivu-col-span-20{
        border-bottom: 1px solid #333333;
        margin-bottom: 10px;
        padding-bottom: 10px;
    }
    .ivu-col.ivu-col-span-20:last-child{
        border-bottom: 0;
    }
    .ivu-col.ivu-col-span-6:last-child{
        padding-right: 0;
    }
    .ivu-table-wrapper-with-border{
        margin-top: 10px;
    }
    .day-num-item{
        margin-top: 10px;
    }
    .ivu-select{
        margin-top: 10px;
    }
</style>
